package com.car.account.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.car.account.dto.adminDto.SelectAdminDto;
import com.car.account.entity.Admin;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 董旭
 * @since 2024-08-28
 */
@Mapper
public interface AdminMapper extends BaseMapper<Admin> {

    @Select({
            "<script>",
            "SELECT a.admin_id AS adminId, a.admin_name AS adminName, a.admin_phone AS adminPhone, pr.role_name AS roleName, a.admin_state AS adminState",
            "FROM admin a",
            "JOIN admin_role ar ON a.admin_id = ar.admin_id",
            "JOIN platform_role pr ON ar.role_id = pr.role_id",
            "<where>",
            "a.admin_name LIKE CONCAT('%', #{adminName}, '%')",
            "AND a.admin_phone LIKE CONCAT('%', #{adminPhone}, '%')",
            "AND a.admin_state != 2",
            "</where>",
            "ORDER BY a.admin_id ASC",
            "</script>"
    })
    Page<SelectAdminDto> findAdminInfo(Page<SelectAdminDto> page,
                                       @Param("adminName") String adminName,
                                       @Param("adminPhone") String adminPhone);

}
